package net.zjitc.service.impl;

import net.zjitc.mapper.CategoryMapper;
import net.zjitc.mapper.ProductMapper;
import net.zjitc.pojo.Category;
import net.zjitc.pojo.Products;
import net.zjitc.service.ProductService;
import net.zjitc.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

/**
 * @Author admin
 * @Date 2019/5/21 10:11
 */
@Service
@Transactional
public class ProductServiceImpl implements ProductService {
    @Autowired
    ProductMapper productMapper;
    @Autowired
    CategoryMapper categoryMapper;
    @Override
    public List<Products> findAll() {
        return productMapper.findAll();
    }

    @Override
    public int add(Products products) {
        return productMapper.add(products);
    }

    @Override
    public void delete(String id) {
        productMapper.delete(id);
    }

    @Override
    public Products findById(String id) {
        return productMapper.findById(id);
    }

    @Override
    public int update(Products products) {
        return productMapper.update(products);
    }

    @Override

        public List<Products> search(ProductVo productVo) {
            List<Products> list = productMapper.search(productVo);
            for (Products product :list){
                Category category = categoryMapper.findById(product.getCid());
                product.setCategory(category);
            }
            return list;
        }


}

